﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Jy123.BLL.User
{
    public class Dynamic
    {
        /// <summary>
        /// 动态列表
        /// </summary>
        /// <param name="userID">当前用户</param>
        /// <param name="self">是否是自己的动态</param>
        /// <param name="cPage">起始页</param>
        /// <param name="pageSize">每页记录数量</param>
        /// <param name="dynType">动态类型</param>
        /// <param name="counts">需要获取的数量</param>
        /// <returns>数据集</returns>
        public DataSet DynList(int userID, bool self, int cPage, int pageSize, string dynType,out List<int?> counts)
        {
            Jy123.Model.MPagination modelPag = new Jy123.Model.MPagination();
            StringBuilder strFilter = new StringBuilder();
            strFilter.AppendFormat("FUser={0}",userID);

            if (!string.IsNullOrEmpty(dynType))
            {
                switch (dynType)//动态类型选择
                {
                    case "blogs"://日志、日志评论
                        strFilter.Append(" and (DynType='blog' or DynType='blogcomment')");
                        break;
                    case "album"://相册：增删改
                        strFilter.Append(" and (DynType='creatlbum' or DynType='dellbum' or DynType='updatealbum')");
                        break;
                    case "mood"://心情
                        strFilter.Append(" and (DynType='mood')");
                        break;
                    case "group"://圈子:添加、加入、退出、发圈子帖、回帖
                        strFilter.Append(" and (DynType='creatgroup' or DynType='joingroup' or DynType='outgroup' or DynType='posttopic' or DynType='replytopic')");
                        break;
                    case "userinfo"://用户信息
                        strFilter.Append(" and (DynType='login' or DynType='info' or DynType='infolink' or DynType='infofav' or DynType='infoName' or DynType='infoAddress' or DynType='headpic' or DynType='inviteJoin')");
                        break;
                    case "friend"://好友
                        strFilter.Append(" and (DynType='friend' or DynType='inviteJoin')");
                        break;
                    case "app"://应用
                        strFilter.Append(" and (DynType='AddApp' or DynType='OutApp')");
                        break;
                    case "0day"://今天之内
                        strFilter.Append("  and datediff(d,CreatTime,getdate())=0");
                        break;
                    case "1day"://一天之内
                        strFilter.Append("  and datediff(d,CreatTime,getdate())=1");
                        break;
                    case "3day"://三天内
                        strFilter.Append("  and datediff(d,CreatTime,getdate())=2");
                        break;
                    case "7day"://一周内
                        strFilter.Append(" and datediff(d,CreatTime,getdate())<=7");
                        break;
                    case "30day"://一个月内
                        strFilter.Append(" and datediff(d,CreatTime,getdate())<=30");
                        break;
                    case "90day"://三个月内
                        strFilter.Append("  and datediff(d,CreatTime,getdate())<=90");
                        break;
                    case "all"://所有
                        strFilter.Append("");
                        break;
                }
            }
            if (self)
            {
                modelPag.Tables = "V_User_DynamicSelf";
            }
            else
            { 
                modelPag.Tables = "V_User_DynamicFriend";
            }
            
            modelPag.PrimaryKey = "ID";
            modelPag.Fields = "*";
            modelPag.Filter = strFilter.ToString();
            modelPag.Sort = "CreatTime DESC,FUser DESC";
            modelPag.Group = string.Empty;
            modelPag.CurrentPage = cPage;
            modelPag.PageSize = pageSize;
            return BLL.Public.Pagination.GetList(modelPag,out counts);

        }
    }
}
